package dk.dashboardFP.message {
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.filters.DropShadowFilter;

	import dk.dashboardFP.DashboardFP;
	import dk.dashboardFP.panels.ui.text.label.AbstractLabel;
	import dk.dashboardFP.shapes.Box;

	import flash.display.Sprite;

	/**
	 * @author josef
	 */
	public class DashbardFPMessage extends Sprite {
		private var _text : String;
		private var _timeOut : Number;
		private var _width : Number = 300;
		private var _infoLabel : AbstractLabel;
		private var _bodyLabel : AbstractLabel;
		private var _margin : Number = 10;
		private var _back : Box;
		private var _timer : Timer;

		public function DashbardFPMessage(text : String, timeOut : Number) {
		
			_timeOut = timeOut;
			_text = text;
			
			setupElements();
		}

		private function setupElements() : void {
			
			// position 
			x = 40;
			y = 40;
			
			// info label
			_infoLabel = new AbstractLabel("DashboardFP v. " + DashboardFP.VERSION, 10, 0x999999, true, "Arial", false);
			addChild(_infoLabel);
			
			// body label 
			_bodyLabel = new AbstractLabel("", 12, 0xeeeeee, true, "Arial", false);
			
			_bodyLabel.y = 18;
			
			_bodyLabel.sHtmlText = _text;
			
			_bodyLabel.bSelectable=true;
			
			addChild(_bodyLabel);
			 
			// back 
			_back = new Box(_bodyLabel.width + 2 * _margin, height + 2 * _margin, 0, 0.75, 8);
			
			_back.filters = [new DropShadowFilter(0, 0, 0, 0.5, 15, 15, 1, 2)];
			
			_back.x = -_margin;
			_back.y = -_margin;
			
			addChildAt(_back, 0);
			
			// setup timeout 
			_timer=new Timer(_timeOut, 1);
			_timer.addEventListener(TimerEvent.TIMER_COMPLETE, kill, false, 0, true);
			_timer.start();
		}

		public function kill(e:Event=null) : void {
			_timer=null;
			if (parent) {
				parent.removeChild(this);
			}
		}
	}
}
